package com.ls.lserp.modules.order.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ls.lserp.common.web.BaseController;
import com.ls.lserp.dbaccess.Entity.InventoryChangeImperfectDetailEntity;
import com.ls.lserp.modules.order.entity.OrderRework;
import com.ls.lserp.modules.order.service.ReworkService;




@Controller

public class ReworkController extends BaseController {

	@Autowired
	private ReworkService reworkService;
	/**
	 * 跳转返工换片画面
	 */
	@RequestMapping(value = "${adminPath}/rework")
	public String rework(int imageFlag,Model model) {
		model.addAttribute("imageFlag", imageFlag);
		return "sys/rework";
	}

	/**
	 * 获取返工换片信息
	 * 
	 * @param produceparameter
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "${adminPath}/reworkInfo")
	public String reworkInfo(OrderRework orderRework,int imageFlag, HttpServletRequest request, HttpServletResponse response, Model model) {
		try {
			orderRework = reworkService.getReworkInfo(orderRework);
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		model.addAttribute("orderInfo",orderRework.getOrder());
		model.addAttribute("itemList",orderRework.getStyleQualityList());
		model.addAttribute("imageFlag", imageFlag);
		// 返回页面地址
		return "sys/rework";
	}
	
	/**
	 * 换片画面
	 */
	@RequestMapping(value = "${adminPath}/changeImperfect")
	public String changeImperfect(OrderRework orderRework,Model model) {
		//获取物料库存数量
		model.addAttribute("inventoryQuantity",reworkService.getInventoryQuantity(orderRework.getOrder().getFabricId()));
		//获取料头数量
		model.addAttribute("remainQuantity",reworkService.getRemainQuantity(orderRework.getOrder().getFabricId()));
		model.addAttribute("materialInfo", orderRework.getOrder());
		model.addAttribute("reworkReason", orderRework.getReworkReason());
		return "sys/changeImperfect";
	}
	
	/**
	 * 保存换片信息
	 */
	@RequestMapping(value = "${adminPath}/saveChangeImperfect")
	public String saveChangeImperfect(InventoryChangeImperfectDetailEntity changeImperfectEntity,String reworkReason,HttpServletResponse response,Model model) {
		String flag = "false";
		try {
			//保存
			reworkService.saveChangeImperfectInfo(changeImperfectEntity,reworkReason);
			flag = "true";
		} catch (Exception e) {
			logger.error(e.getMessage(),e);
		}
		return renderString(response, flag);
	}
	

}